package com.haha.extend.HeadBar;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;

import com.Long.library.R;
import com.haha.extend.textview.CustomFontTextView;

/**
 * Created by Administrator on 2016/6/24 0024.
 */
public class BaseTitleBar extends BaseHeaderView{
    private String titleText;
    private CustomFontTextView titleView;
    private int titleTextColor;
    private float titleTextSize;
    protected String fontPath;
    public BaseTitleBar(Context context) {
        super(context);
    }

    public BaseTitleBar(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public BaseTitleBar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void getAttrs(AttributeSet attrs) {
        super.getAttrs(attrs);
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.BaseTitleBar);
        titleText = ta.getString(R.styleable.BaseTitleBar_titleText);
        titleTextColor = ta.getColor(R.styleable.BaseTitleBar_titleTextColour, Color.WHITE);
        titleTextSize = ta.getDimension(R.styleable.BaseTitleBar_titleTextSize,28);
        fontPath = ta.getString(R.styleable.BaseTitleBar_titleFontInAssets);
        ta.recycle();
    }

    @Override
    protected void findView() {
        super.findView();
        titleView = new CustomFontTextView(context);
    }

    @Override
    protected void initView() {
        super.initView();
        titleView.setText(titleText);
        titleView.setTextColor(titleTextColor);
        titleView.setTextSize(titleTextSize);
        titleView.setCustomFontInAssets(fontPath);
    }

    public void setTitleText(String str){
        titleView.setText(str == null ? "" : str);
    }

    public void setTitleText(int strResId){
        titleView.setText(strResId);
    }

    @Override
    public View getLeftView() {
        return null;
    }

    @Override
    public View getCenterView() {
        return titleView;
    }

    @Override
    public View getRightView() {
        return null;
    }
}
